const express = require('express')
const cors = require('cors')
const initRouter = require('./router')

const app = express()

// 解决跨域
app.use(cors())
app.all('*', function (req, res, next) {
	res.header('Access-Control-Allow-Origin', '*')
	res.header('Access-Control-Allow-Headers', 'content-type')
	res.header('Access-Control-Allow-Methods', 'DELETE,PUT,POST,GET,OPTIONS')
	if (req.method === 'OPTIONS') res.send(200)
	else next()
})
// 添加路由
// app.use(router)
initRouter(app)
app
	.listen(9001, () => {
		// console.log('start success.')
	})
	.on('error', e => {
		console.error(e.code, e.message)
	})
